// 1. 两数之和

function twoSum(nums: number[], target: number): number[] {
  const map = new Map<number, number>();
  nums.forEach((item, index) => map.set(item, index));

  // let ins:number = 0

  for (let i = 0; i < nums.length; i++) {
    const ins: number = target - nums[i];
    console.log(ins, nums[i]);
    if (map.has(ins) && i !== map.get(ins)) {
      return [i, map.get(ins)];
    }
  }

  return [-1, -1];
}

const nums22 = [2, 7, 11, 15],
  target4 = 9;

console.log(twoSum(nums22, target4));
